from django.http import JsonResponse
from remind.models import RemindModel
from scheduler.scheduler import RemindScheduler
from django.db.models.signals import post_save
import logging
logger=logging.getLogger(__name__)
from rest_framework.views import APIView,Response
class Start(APIView):
    def get(self,request):
        logging.basicConfig(level=logging.INFO,format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        logger.info("调度器已启动")
        scheduler = RemindScheduler()
        scheduler.start()
        post_save.connect(lambda *a, **k: scheduler.wakeup(),
                          sender=RemindModel,
                          weak=False,
                          dispatch_uid='update-scheduler1')
        return Response({'result': True, 'message': "用于测试环境的启动调度器，真实环境应取消"})
